package com.rtx.wms.std.job.transfer;

import java.util.List;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.rtx.api.annotation.RtxJobAnnotation;
import com.rtx.api.quartz.job.BaseJob;
import com.rtx.wms.std.common.bean.WmsConstant;
import com.rtx.wms.std.common.service.CommonService;
import com.rtx.wms.std.handler.transfer.finsh.TransferFinishHandler;

@Component
@DisallowConcurrentExecution
@RtxJobAnnotation(jobName = "TransferFinishJob",description = "调拨单回传写入中间表",cron = "0/30 * * * * ?")
public class TransferFinishJob implements BaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TransferFinishHandler transferFinishHandler;

    @Autowired
    private CommonService commonService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //激活的仓库
        List<String> whseidList = commonService.selectActiveWhseidNotEnterprise(WmsConstant.ENTERPRISE);
        
        for(String whseid : whseidList){
            try {
            	if(!whseid.startsWith("wmwhse")) {
            		continue;
            	}
            	transferFinishHandler.handlerOrdersFinish(whseid);
            } catch (Exception e) {
                logger.error("仓库{}调拨单回传写入中间表异常",whseid,e);
            }
        }
    }
}
